package com.xb.loan.util.qrtz.listener;


import com.xb.loan.util.log.DefaultLoggerFacotry;
import com.xb.loan.util.qrtz.task.Task;
import org.slf4j.Logger;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * 
 *  监听器 注册， 触发， 支撑类
 * @author wuql
 */
public class TaskListenerSupport {
	protected Logger logger = DefaultLoggerFacotry.getLogger(getClass());
	private List<TaskListener> listeners = new CopyOnWriteArrayList<TaskListener>();

	public void setListeners(List<TaskListener> listeners) {
		this.listeners = listeners;
	}

	public void add(TaskListener listener) {
		if (listener != null) {
			listeners.add(listener);
		}
	}

	public void remove(TaskListener listener) {
		if (listener != null) {
			listeners.remove(listener);
		}
	}

	public void fireTaskCreate(Task task) {
		for (TaskListener listener : listeners) {
				listener.taskCreate(task);
		}
	}

	public void fireTaskToBeExecuted(Task task) {
		for (TaskListener listener : listeners) {
				listener.taskToBeExecuted(task);
		}
	}

	public void fireTaskExecutionVetoed(Task task) {
		for (TaskListener listener : listeners) {
				listener.taskExecutionVetoed(task);
		}
	}

	public void fireTaskWasExecuted(Task task) {
		for (TaskListener listener : listeners) {
				listener.taskWasExecuted(task);
		}
	}

}
